const { ethers } = require("hardhat");

async function main() {
  // 获取钱包列表，假设第一个钱包是发送者
  // const [sender, recipient] = await ethers.getSigners();
  
  // 提供具体的发送者私钥
  // const senderPrivateKey = "32630e2a886428718d198f3f1e4df156918e995a9026967b632f8a750765ed2b";
  const senderPrivateKey = "0b6cb6ebaabb9d2ec2611b7d131efdae2d18988afe7a1f6e07f49c9821e626d7";
  
  // 创建一个签名器实例
  const sender = new ethers.Wallet(senderPrivateKey, ethers.provider); 
  
  // 提供接收者的地址
  const recipientAddress = "0x01f5219F13a193Db57f953b8bd9365185cB25bb2";

  // 转账金额（以 wei 为单位）
  const amount = ethers.parseEther("1000") // 1000 ETH

  // 手动设置交易的 nonce 值
  const nonce = await sender.getNonce()
  console.log("Current nonce:", nonce);

  // 发送交易
  console.log(`Transferring 1000 ROOS from ${sender.address} to${recipientAddress}`);
  const tx = await sender.sendTransaction({
    to: recipientAddress,
    nonce: nonce,
    value: amount
  });

  // 等待交易被矿工确认
  console.log("Waiting for transaction to be confirmed...");
  await tx.wait();

  // 输出交易详情
  console.log(`Transaction confirmed: https://roos.io/tx/${tx.hash}`);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });
